package com.winchain.chainbill.bill.biz.discount.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.modules.message.keyword.SysDctApplyKeyword;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.stereotype.Component;

@Component
public class BillDctMsgSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbDct>> {
	public void onApplicationEvent(BillEvent<CbDct> t) {
		CbDct cbDct = (CbDct) t.getBill().getSource();

		String template = "MT01611";
		SysDctApplyKeyword keyWord = new SysDctApplyKeyword();
		keyWord.setDctAmt(String.valueOf(cbDct.getDctAmt()));

		String dctDate = SysDateUtil.parseDate(cbDct.getDctDate(), "yyyyMMdd", "yyyy-MM-dd");
		keyWord.setDctDate(dctDate);
		keyWord.setContactorName(CommonDataUtil.getUserName());

		String senderId = CommonDataUtil.getUserId();
		MessageSender.sendMessageByTmpl(senderId, template, keyWord, cbDct.getSellerId());
	}
}
